<div class="main layui-clear">
    <div class="wrap">
        <div class="content detail">
            <div class="fly-panel detail-box"><h1><?php echo $info['title'] ?></h1>
                <div class="fly-tip fly-detail-hint">
                    <?php if (in_array('1', explode(',', $info['state']))) { ?>
                        <span class="fly-tip-stick">置顶帖</span>
                    <?php } ?>
                    <?php if (in_array('2', explode(',', $info['state']))) { ?>
                        <span class="fly-tip-jing">精帖</span>
                    <?php } ?> 
                    
                    <?php if ($info['status']==0) { ?>
                       <span>未结贴</span>
                    <?php } ?>
                    <?php if ($info['status']==1) { ?>
                      <span class="fly-tip-jie">已采纳</span>
                    <?php } ?>
                    <div class="jie-admin-box" data-id="8815"></div>
                    <div class="fly-list-hint"><a href="javascript:;"><i class="iconfont"  title="回答"></i><?php echo $info['answer_num'] ?></a> <i class="iconfont" title="人气"></i> <?php echo $info['view_num'] ?>
                    </div>
                </div>
                <div class="detail-about"><a class="jie-user" href="{:U('home/u/index',array('id'=>$info['uid']))}"> <img
                        src="__ROOT__<?php echo $info['face'] ?>" alt="<?php echo $info['nickname'] ?>"> <cite> <?php echo $info['nickname'] ?><em>发布于<?php echo CT($info['create_time']) ?></em>
                </cite> </a>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="8815">
                        <span style="color:#FF7200">悬赏：<?php echo $info['kiss_num'] ?>飞吻</span>
                        <?php if ($info['status']==0) { ?>
                            <?php if ($info['uid']==$_SESSION['id']) { ?>
                                <span class="layui-btn layui-btn-mini jie-admin" type="edit">
                                    <a href="{:U('home/wen/editquestion',array('id'=>$info['id']))}">编辑此贴</a>
                                </span>
                            <?php } ?>
                        <?php } ?>

                        
                        <?php if (empty($store)) { ?>
                            <span class="layui-btn layui-btn-mini jie-admin shoucang" qid='<?php echo $info['id'] ?>' type="collect" data-type="add">收藏</span></div>
                        <?php }else{ ?>
                            <span class="layui-btn layui-btn-mini jie-admin layui-btn-danger shoucang" qid='<?php echo $info['id'] ?>' type="collect" data-type="add">取消收藏</span></div>
                        <?php } ?>
                        
                </div>
                <div class="detail-body photos"><?php echo htmlspecialchars_decode($info['content'])  ?></div>
            </div>

            <div class="fly-panel detail-box" style="padding-top: 0;">
                <ul class="jieda photos" id="jieda">
                    <?php  if (empty($ifanswer)) { ?>
                    <li class="fly-none">没有任何回答</li>
                    <?php }else{ ?>

                    <?php  foreach ($asinfo as $k => $v) { ?>
                         <li data-id="30213"><a name="item-1490877237136"></a>
                            <div class="detail-about detail-about-reply">
                                <a class="jie-user" href="{:U('home/u/index',array('id'=>$v['uid']))}">
                                    <img src="__ROOT__<?php echo $v['face'] ?>" alt="<?php echo $v['nickname'] ?>" layer-index="2">
                                    <cite> <i><?php echo $v['nickname'] ?></i></cite>
                                </a>
                                <div class="detail-hits">
                                    <span><?php echo CTS($v['create_time']) ?></span>
                                </div>
                                <?php if ($v['status']==1) { ?>
                                    <i class="iconfont icon-caina" title="最佳答案"></i>
                                <?php } ?>
                            </div>
                            <div class="detail-body jieda-body"> <?php echo htmlspecialchars_decode($v['content']) ?></div>
                            <div class="jieda-reply">
                                <?php if ($v['fuid']=='') { ?>
                                    <span class="jieda-zan" type="zan" answerid="<?php echo $v['id'] ?>">
                                        <i class="iconfont icon-zan"></i>
                                        <em><?php echo $v['zan_num'] ?></em>
                                    </span>
                                <?php }else{ ?>
                                    <span style="color:#c00" class="jieda-zan" type="zan" answerid="<?php echo $v['id'] ?>">
                                        <i class="iconfont icon-zan"></i>
                                        <em><?php echo $v['zan_num'] ?></em>
                                    </span>
                                <?php } ?>
                                    
                                    <span type="reply" class="reply" ansid="<?php echo $v['id'] ?>" name="<?php echo $v['nickname'] ?>">
                                        <i class="iconfont icon-svgmoban53"></i>回复
                                    </span>
                                    <?php if ($info['status']==0) { ?>
                                        <?php if ($info['uid']==$_SESSION['id']) { ?>
                                            <?php if ($v['uid']!=$_SESSION['id']) { ?>
                                            <div class="jieda-admin">
                                                <span class="jieda-accept" aid='<?php echo $v['id'] ?>' type="accept">采纳</span>
                                            </div>
                                            <?php } ?> 
                                        
                                        <?php } ?>
                                    <?php } ?>

                            </div>
                        </li>
                    <?php } ?>
              <?php  } ?>
                </ul>
                <div class="layui-form-pane">
                    <form method="post">
                        <div class="layui-form-item layui-form-text"><a name="comment"></a>
                            <div class="layui-input-block">
                                <textarea id="L_content" name="content" required="" lay-verify="required" placeholder="我要回答" class="layui-textarea fly-editor"style="height: 150px;">
                                </textarea>
                            </div>
                        </div>
                        <div class="layui-form layui-form-item">
                            <input type="hidden" name="qid" value="<?php echo $info['id'] ?> ">
                            <input type="hidden" class="answerid" name="answerid" value="">
                            <button class="layui-btn" lay-filter="asadd" lay-submit="">提交回答</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="edge">
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">最近热帖</dt>
            <?php foreach ($hotview as $row) { ?>
                <dd>
                    <a href="{:U('home/contg/index',array('id'=>$row['id']))}"><?php echo $row['title'] ?></a>
                    <span><i class="iconfont"></i><?php echo $row['view_num'] ?></span>
                </dd>
           <?php } ?>

        </dl>
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">近期热议</dt>
            <?php foreach ($hotanswer as $row) { ?>
                <dd>
                    <a href="{:U('home/contg/index',array('id'=>$row['id']))}"><?php echo $row['title'] ?></a>
                    <span><i class="iconfont"></i><?php echo $row['answer_num'] ?></span>
            </dd>
            <?php } ?>
        </dl>
    </div>
</div>
<script>
    layui.use(['form','jquery','layedit'], function(){
        var form = layui.form(),
            layer = layui.layer,
            $= layui.jquery,
            layedit = layui.layedit;


            layedit.set({
              uploadImage: {
                url: '{:U('home/wen/uploadpic')}' //接口url
                ,type: '' //默认post
              }
            });


        index = layedit.build('L_content', {
          height: 180 //设置编辑器高度
        });

                    //  回复-》回复
        $('.reply').click(function() {
            ansid=$(this).attr('ansid');
            name=$(this).attr('name');
            $('.answerid').val(ansid)
            str = '@'+name+'&nbsp;';

            layedit.setContent(index,str);
            layedit.xbsfocus(index);
            
            

            

        });

        //监听提交
        form.on('submit(asadd)', function(data){

            //获取编辑器里的内容
            content=layedit.getContent(index);
            data.field.content = content;

            index = layedit.build('L_content', {
              height: 180 //设置编辑器高度
            });
            // alert(content);
            //判断编辑器内容长度
            if (content.length<10) {
                layer.msg('问题长度不得小于10字符');
                return false;
            };
            // alert(data.field.content)
        //提交回复
        $.ajax({
            url: '{:U('home/contg/asadd')}',
            type: 'POST',
            dataType: 'json',
            data: data.field,
           })
           .done(function(respones) {
             if (respones.error==1) {
                layer.msg(respones.info);
             }else{

                layer.alert(respones.info, {icon: 6},function  () {
                    location.reload()
                    });
                }
            })
           .fail(function() {
              console.log("error");
           })

            return false;
        })
        //点赞
        $('.jieda-zan').click(function(data) {
            zan=$(this);
            data=$(this).attr('answerid');
            $.ajax({
                url:  '{:U('home/contg/Zan_Answer')}',
                type: 'POST',
                dataType: 'json',
                data: {data: data},
            })
            .done(function(data) {
                if (data.error==0) {
                    layer.msg(data.info);
                }else if (data.error==1) {
                        num=parseInt(zan.children('em').html());
                        num=num+1;
                        zan.children('em').html(num);
                        zan.css('color','#c00');
                        // zan.children('em').siblings('i').css{'color','#c00'}
                    }else if (data.error==2) {
                        num=parseInt(zan.children('em').html());
                        num=num-1;
                        zan.children('em').html(num);
                        zan.css('color','#999');
                };;
            })
            .fail(function() {
                console.log("error");
            })
            
        });
        // 收藏
        $('.shoucang').click(function(data) {
            data=$(this).attr('qid');
            $.ajax({
                url: '{:U('home/contg/store')}',
                type: 'POST',
                dataType: 'json',
                data: {data: data},
            })
            .done(function(data) {
                if (data.error==0) {
                    layer.msg(data.info);
                }else if (data.error==1) {
                     layer.msg(data.info)
                     $('.shoucang').addClass('layui-btn-danger').html('取消收藏');
                    }else if (data.error==2) {
                       layer.msg(data.info)
                       $('.shoucang').removeClass('layui-btn-danger').html('收藏');
                };
            })
            .fail(function() {
                console.log("error");
            })
            
        })
        //采纳
        $('.jieda-accept').click(function(data) {
            data=$(this).attr('aid');
            $.ajax({
                url: '{:U('home/contg/adopt')}',
                type: 'POST',
                dataType: 'json',
                data: {aid: data},
            })
            .done(function(data) {
                if (data.error==1) {
                    layer.alert(data.info, {icon: 6},function  () {
                    location.reload()
                    });
                }else{
                    layer.msg(data.info);
                };
            })
            .fail(function() {
                console.log("error");
            })
            
        });




    });

    
    
</script>